import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { OrderApi } from '#/api/wedding/weddingorder';

import { z } from '#/adapter/form';
import {
    DICT_Wedding_TYPE,
    getDictOptions,
    getRangePickerDefaultProps,
} from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'orderId',
      label: '订单ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入订单ID',
      },
    },
    {
      fieldName: 'customerId',
      label: '客户ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入客户ID',
      },
    },
    {
      fieldName: 'weddingDate',
      label: '婚礼日期',
      rules: 'required',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'totalAmount',
      label: '订单总额',
      component: 'Input',
      componentProps: {
        placeholder: '请输入订单总额',
      },
    },
    {
      fieldName: 'discountAmount',
      label: '优惠金额',
      component: 'Input',
      componentProps: {
        placeholder: '请输入优惠金额',
      },
    },
    {
      fieldName: 'finalAmount',
      label: '实付金额',
      component: 'Input',
      componentProps: {
        placeholder: '请输入实付金额',
      },
    },
    {
      fieldName: 'paidAmount',
      label: '已付金额',
      component: 'Input',
      componentProps: {
        placeholder: '请输入已付金额',
      },
    },
    {
      fieldName: 'packageId',
      label: '套餐ID',
      component: 'Input',
      componentProps: {
        placeholder: '请输入套餐ID',
      },
    },
    {
      fieldName: 'orderStatus',
      label: '订单状态',
      component: 'RadioGroup',
      componentProps: {
        options: getDictOptions(DICT_Wedding_TYPE.HandCardTypeStatus.toUpperCase(), 'string'),
        buttonStyle: 'solid',
        optionType: 'button',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'orderId',
      label: '订单ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入订单ID',
      },
    },
    {
      fieldName: 'customerId',
      label: '客户ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入客户ID',
      },
    },
    {
      fieldName: 'weddingDate',
      label: '婚礼日期',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'totalAmount',
      label: '订单总额',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入订单总额',
      },
    },
    {
      fieldName: 'discountAmount',
      label: '优惠金额',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入优惠金额',
      },
    },
    {
      fieldName: 'finalAmount',
      label: '实付金额',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入实付金额',
      },
    },
    {
      fieldName: 'paidAmount',
      label: '已付金额',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入已付金额',
      },
    },
    {
      fieldName: 'packageId',
      label: '套餐ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入套餐ID',
      },
    },
    {
      fieldName: 'orderStatus',
      label: '订单状态',
      component: 'Select',
      componentProps: {
        allowClear: true,
        options: getDictOptions(DICT_Wedding_TYPE.HandCardTypeStatus.toUpperCase(), 'string'),
        placeholder: '请选择订单状态',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<OrderApi.Order>['columns'] {
  return [
    {
      field: 'id',
      title: '',
      minWidth: 120,

    },
    {
      field: 'orderId',
      title: '订单ID',
      minWidth: 120,

    },
    {
      field: 'customerId',
      title: '客户ID',
      minWidth: 120,

    },
    {
      field: 'weddingDate',
      title: '婚礼日期',
      minWidth: 120,

    },
    {
      field: 'totalAmount',
      title: '订单总额',
      minWidth: 120,

    },
    {
      field: 'discountAmount',
      title: '优惠金额',
      minWidth: 120,

    },
    {
      field: 'finalAmount',
      title: '实付金额',
      minWidth: 120,

    },
    {
      field: 'paidAmount',
      title: '已付金额',
      minWidth: 120,

    },
    {
      field: 'packageId',
      title: '套餐ID',
      minWidth: 120,

    },
    {
      field: 'orderStatus',
      title: '订单状态',
      minWidth: 120,

    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}

